package com.yan.kfgl.web;

import ins.yan.framework.model.Page;

import java.util.List;

import org.apache.struts2.json.annotations.JSON;

import com.yan.kfgl.model.Jtext;
import com.yan.kfgl.service.biz.facade.JtextService;

public class JtextAction {

	private Page page;
	private String idsStr;
	private String info;
	private Jtext jtext;
	private List<Jtext> jtextList;
	
	private JtextService jtextService;
	
	public String prepareAddJtext(){
		
		return "success";
	}

	public String addJtext(){
		jtextService.insertJtext(jtext);
		//jtextList = jtextService.loadJtextList(page, info);
		//return "success";
		return "chainlistJtext";
	}
	
	public String prepareEditJtext(){
		jtext = jtextService.loadJtextByPK(jtext);
		return "success";
	}
	
	public String editJtext(){
		jtextService.editJtext(jtext);
		//jtextList = jtextService.loadJtextList(page, info);
		//return "success";
		return "chainlistJtext";
	}
	
	public String listJtext(){
		if(page == null){
			page = new Page();
		}
		if(info == null || "\"\"".equals(info)){
			info = "";
		}
		long total = jtextService.findJtextListTotalPage(page , info);
		page.setTotalPage(total);
		jtextList = jtextService.loadJtextList(page, info);
		return "success";
	}
	
	public String viewJtext(){
		jtext = jtextService.loadJtextByPK(jtext);
		return "success";
	}
	
	public String deleteJtext(){
		System.out.println(idsStr);
		String[] strs = idsStr.split(",");
		Integer[] ids = new Integer[strs.length];
		for(int i=0;i<strs.length;i++){
			ids[i] = Integer.parseInt(strs[i]);
		}
		System.out.println(ids.length);
		//jtextService.dropJtext(jtext);
		jtextService.dropJtextListByIds(ids);
		return "none";
	}
	
	@JSON(serialize=false)
	public Jtext getJtext() {
		return jtext;
	}

	public void setJtext(Jtext jtext) {
		this.jtext = jtext;
	}
	
	@JSON(serialize=false)
	public List<Jtext> getJtextList() {
		return jtextList;
	}
	
	public void setJtextList(List<Jtext> jtextList) {
		this.jtextList = jtextList;
	}

	@JSON(serialize=false)
	public JtextService getJtextService() {
		return jtextService;
	}

	public void setJtextService(JtextService jtextService) {
		this.jtextService = jtextService;
	}

	@JSON(serialize=false)
	public String getIdsStr() {
		return idsStr;
	}

	public void setIdsStr(String idsStr) {
		this.idsStr = idsStr;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public String getInfo() {
		return info;
	}

	public void setInfo(String info) {
		this.info = info;
	}

}